from Common.CompanyOrg import Company
from Common.Profile import Profile
from Utility import IsEmptyString
from google.appengine.ext.db import BadKeyError

def LogIn(userName, passWord, companyName):
    if IsEmptyString(companyName):
        c = None
    else:
        c = Company.get_by_key_name(companyName)

    u = Profile.get_by_key_name(userName, c)
    if (u is not None) and (u.Password == passWord):
        return u
    else:
        return None
    
def GetProfileInfo(key):
    if key is None:
        return None
#    q = Profile.gql("Where UserName=:username", username=userName).get()
    try:
        q=Profile.get(key)
        return q
    except BadKeyError:
        return None
    